#pragma once
#include "stdlib/timestamp.hpp"
using namespace JHCPP::stdlib;
#include <map>
#include <string>

namespace JHCPP
{
	namespace log
	{
		class CMessage
		{
		public:
			enum Priority
			{
				PRIO_FATAL = 1,
				PRIO_CRITICAL,
				PRIO_ERROR,
				PRIO_WARNING,
				PRIO_NOTICE,
				PRIO_INFORMATION,
				PRIO_DEBUG,
				PRIO_TRACE
			};

			CMessage();
			CMessage(const std::string& source, const std::string& text, Priority prio);
			CMessage(const std::string& source, const std::string& text, Priority prio, const char* file, int line);
			CMessage(const CMessage& msg);
			CMessage(const CMessage& msg, const std::string& text);

			~CMessage();

			CMessage& operator = (const CMessage& msg);
			void swap(CMessage& msg);

			void setSource(const std::string& src);
			const std::string& getSource() const;

			void setText(const std::string& text);
			const std::string& getText() const;

			void setPriority(Priority prio);
			Priority getPriority() const;
	
			void setTime(const CTimeStamp& time);
			const CTimeStamp& getTime() const;
	
			void setThread(const std::string& thread);
			const std::string& getThread() const;

			void setTid(long pid);
			long getTid() const;

			void setPid(long pid);
			long getPid() const;

			void setSourceFile(const char* file);
			const char* getSourceFile() const;

			void setSourceLine(int line);
			int getSourceLine() const;

			const std::string& operator [] (const std::string& param) const;
			std::string& operator [] (const std::string& param);

		protected:
			void init();
			typedef std::map<std::string, std::string> StringMap;

		private:	
			std::string m_source;
			std::string m_text;
			Priority    m_prio;
			CTimeStamp  m_time;
			int         m_tid;
			std::string m_thread;
			long        m_pid;
			const char* m_file;
			int         m_line;
			StringMap*  m_pMap;
		};

		inline void swap(CMessage& m1, CMessage& m2)
		{
			m1.swap(m2);
		}

	}//end of namespace log
}//end of namespace JHCPP
